﻿<%@ Page Title="" Language="C#" MasterPageFile="~/management/Site.Master" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
   <script src="../js/jquery-1.7.1.min.js" type="text/javascript"></script>    
    <script src="../js/jquery.ui.js" type="text/javascript"></script>
    <script src="../js/repeater.js" type="text/javascript"></script>
    <script src="../js/pager.js" type="text/javascript"></script>  
    <link href="../styles/pager.css" rel="stylesheet" type="text/css" />
    <link href="../styles/style.css" rel="stylesheet" type="text/css" />        
    <script src="../js/jquery.query.js" type="text/javascript"></script>
    <script src="../js/blockUI.js" type="text/javascript"></script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <table id="search_table">
        <tr>
            <td class="tdtitle">
                名称
            </td>
            <td  class="tdcontent"><input id="s_title" name="s_title" type="text"  size="50"/></td>
             <td class="tdtitle" style="width:50px;">
                            地区：
                        </td>
                        <td colspan="2">
                            国家
                            <select id="country" name="country">
                            </select>
                            省<select id="province" name="province" disabled="disabled"></select>
                            市
                            <select id="city" name="city" disabled="disabled">
                            </select>
                        </td>
             <td class="tdtitle" style="width:100px;">
                发布状态
            </td>
            <td class="tdcontent">
                <select id="s_ispublish" name="s_ispublish">
                <option value="">全部</option>
                <option value="是">发布</option>
                <option value="否">未发布</option>
                </select>
            </td>
            <td>
                <input id="btn_search" value="搜索"  type="button"/>
            </td>
        </tr>
        <tr><td colspan="8"> <input id="btn_delete" type="button" value="批量删除" /> <input id="btn_publish" value="批量发布"  type="button"/> <input id="btn_publishcancel" value="取消发布"  type="button"/><a href="Edit.aspx?code=-1">新增</a></td></tr>
    </table>
    <table id="list">
        <thead>
            
            <tr>
                <th>
                    <input type="checkbox" id="chkall" />全选
                </th>
                <th>
                    景点名称
                </th>
                <th>
                    类型
                </th>
                <th>
                    地区
                </th>
                <th>发布</th>
                <th>
                    编辑
                </th>

                <th>
                    排序
                </th>
                <th>
                    删除
                </th>
            </tr>
        </thead>
        <tbody>
            <!--<tr><td><input type="checkbox" class="chkitem" value='[Code]' /></td><td><a href="/detail.html?id=[Code]" target="_blank">[Title]</a></td><td>[TourType]</td><td>[Region]</td><td>[IsPublish]</td><td><span class="edit" code="[Code]"><a href="Edit.aspx?code=[Code]">编辑</a></span></td><td><span class="up" code='[Code]'>向上</span>&nbsp;<span class="down" code='[Code]'>向下</span></td><td><span class="delete" code='[Code]'>删除</span></td></tr>-->
        </tbody>
        <tfoot>
            <tr>
                <td colspan="8">
                    <div id="pager" psize='15'>
                    </div>
                </td>
            </tr>
        </tfoot>
    </table>
     <input type="hidden" id="hidcountryregion" name="hidcountryregion" />
    <script type="text/javascript">
        $(function () {
            var $list = $("#list>tbody:first");
            var typecode = $.query.get("typecode");
            //绑定列表方法
            var BindData = function () {
                $("#chkall").removeAttr("checked");
                $("#chkall").data("ids", "");
                $.blockUI({ message: "<h2>数据加载中.......</h2>", css: { width: "300px", height: "50px"} });
                $list.template({ autoBind: false });
                $.ajax({ url: "../AjaxHandler/TourismInfoList.ashx?t=" + new Date(),
                    data: {
                        pindex: 1,
                        psize: $("#pager").attr("psize"),
                        action: "List",
                        typecode: typecode,
                        title: $("#s_title").val(),
                        regionpath: $("#hidcountryregion").val(),
                        publish: $("#s_ispublish").val()

                    },
                    type: "post",
                    success: function (data) {
                        pcount = data.Data.Pager.PageCount;
                        $("#pager").pager({ pagenumber: 1, pagecount: pcount, buttonClickCallback: PageClick });
                        $list.template("bindData", data.Data.Rows);
                        $.unblockUI();

                    }
                });
               }
            BindData();
            //分页标签事件
            var PageClick = function (pageclickednumber) {
                $.blockUI({ message: "<h2>数据加载中.......</h2>", css: { width: "300px", height: "50px"} });
                $("#pager").pager({ pagenumber: pageclickednumber, pagecount: pcount, buttonClickCallback: PageClick });
                $.ajax({ url: "../AjaxHandler/TourismInfoList.ashx?t=" + new Date(),
                    data: {
                        pindex: pageclickednumber,
                        psize: $("#pager").attr("psize"),
                        action: "List",
                        typecode: typecode
                    },
                    type: "post",
                    success: function (data) {
                        $list.template("bindData", data.Data.Rows);
                        $.unblockUI();
                    }
                });
            }
            //高亮选中行
            $list.delegate("tr", "mouseover", function () {
                $(this).addClass("altertr");
            });
            //取消高亮选中行
            $list.delegate("tr", "mouseout", function () {
                $(this).removeClass("altertr");
            });
            //排序开始
            $list.delegate("span.up", "click", function () {
                var code = $(this).attr("code");
                Order(true, code); //向上排序
            });

            $list.delegate("span.down", "click", function () {
                var code = $(this).attr("code");
                Order(false, code); //向下排序
            });

            //排序函数
            var Order = function (moveUp, id) {
                $.post("../AjaxHandler/TourismInfoList.ashx?t=" + new Date(), { action: "Order", up: moveUp, code: id }, function (d) {
                    if (d == "1") {
                        BindData();
                    } else {
                        alert("排序失败！");
                    }
                })
            }


            //排序结束

            //单个删除开始
            $list.delegate("span.delete", "click", function () {
                if (confirm("确定要删除吗？")) {
                    var id = $(this).attr("code");
                    $.post("../AjaxHandler/TourismInfoList.ashx?t=" + new Date(), { action: "Delete", code: id }, function (d) {
                        if (d == "1") {
                            alert("删除成功！");
                            BindData();
                        } else {
                            alert("删除失败！");
                        }
                    })
                }
            })
            //单个删除结束
            //批量删除开始
            $("#btn_delete").click(function () {
               
                    var ids = $("#chkall").data("ids");
                    if (typeof (ids) == "undefined") {
                        alert("请选择要删除的项！");
                        return;
                    } else {
                        if (ids.length == 0) {
                            alert("请选择要删除的项！");
                            return;
                        }
                        if (confirm("确定要删除吗？")) {
                        $.post("../AjaxHandler/TourismInfoList.ashx?t=" + new Date(), { action: "DeleteAll", ids: ids, tablename: "TourismInfo" }, function (d) {
                            if (d) {
                                alert("删除成功！");
                                BindData();
                                $("#chkall").data("ids", "");
                            } else {
                                alert("删除失败！");
                            }
                        });
                    }
                }
            })
            //批量删除结束

            //全选开始
            $("#chkall").click(function () {
                if ($(this).attr("checked")) {
                    $("input[type=checkbox]").attr("checked", $(this).attr("checked"));
                    var ids = new Array();
                    $("input.chkitem").each(function () {
                        ids += "'" + $(this).val() + "',";
                    })
                    $(this).data("ids", ids);
                } else {
                    $("input[type=checkbox]").removeAttr("checked");
                    $(this).data("ids", "");
                }
            });
            //全选结束
            //单选开始
            $list.delegate(".chkitem", "click", function () {
                if ($(this).attr("checked")) {
                    if ($("#chkall").data("ids") != null) {
                        $("#chkall").data("ids", $("#chkall").data("ids") + "'" + $(this).val() + "',");
                    } else {
                        $("#chkall").data("ids", "'" + $(this).val() + "',");
                    }
                } else {
                    $("#chkall").data("ids", $("#chkall").data("ids").replace("'" + $(this).val() + "',", ""));
                }
            });
            //单选结束

            //发布开始
            $("#btn_publishcancel").click(function () {
                Publish(false);
            });
            $("#btn_publish").click(function () {
                Publish(true);
            });

            //发布函数
            var Publish = function (p) {
                var ids = $("#chkall").data("ids");
                if (typeof (ids) == "undefined") {
                    alert("请选择要发布的项！");
                    return;
                } else {
                    if (ids.length == 0) {
                        alert("请选择要发布的项！");
                        return;
                    }
                    $.post("../AjaxHandler/TourismInfoList.ashx?t=" + new Date(), { action: "Publish", publish: p, ids: ids }, function (d) {
                        if (d) {
                            BindData();
                        } else {
                            alert("发布失败！");
                        }
                    });
                }

            }
            //发布结束

            //国家地区开始
            ///绑定国家地区select函数
            var BindCountryRegion = function (sel, level, reg) {
                $.ajax({ url: "../AjaxHandler/CountryRegionSelect.ashx?t=" + new Date(), async: false, data: { region: reg, level: level }, success: function (d) {
                    if (d.length > 0) {
                        $("#" + sel).removeAttr("disabled");
                        $("#" + sel).html("");
                        $("#" + sel).append("<option value='-1'>--请选择--</option>");
                        for (var i = 0; i < d.length; i++) {
                            $("#" + sel).append("<option value='" + d[i] + "'>" + d[i] + "</option>");
                        }

                    } else {
                        $("#" + sel).html("");
                        $("#" + sel).attr("disabled", "disabled");
                    }

                }
                });

            }
            BindCountryRegion("country", 0, "");

            //国家选择事件
            $("#country").change(function (event, provincevalue) {

                $("#hidcountryregion").val($(this).val());

                BindCountryRegion("province", 2, $(this).val());
                if (typeof (provincevalue) != "undefined") {
                    $("#province").val(provincevalue);
                }
                if ($(this).val() == "-1") {
                    $("#hidcountryregion").val("");
                    $("#city").html("").attr("disabled", "disabled");
                }
            });
            //省份选择事件
            $("#province").change(function (event, cityvalue) {
                $("#hidcountryregion").val("");
                $("#hidcountryregion").val($("#country").val() + "," + $(this).val());
                BindCountryRegion("city", 3, $(this).val());
                if (typeof (cityvalue) != "undefined") {
                    $("#city").val(cityvalue);
                }
                if ($(this).val() == "-1") {
                    $("#hidcountryregion").val($("#country").val());
                }
            });

            //城市选择事件          
            $("#city").change(function () {
                $("#hidcountryregion").val("");
                $("#hidcountryregion").val($("#country").val() + "," + $("#province").val() + "," + $(this).val());
                if ($(this).val() == "-1") {
                    $("#hidcountryregion").val($("#country").val() + "," + $("#province").val());
                }

            });
            //国家地区结束


            //搜索按钮事件开始
            $("#btn_search").click(function () {
                BindData();
            });
            //搜索按钮事件结束

        })
    </script>
</asp:Content>
